#! /usr/bin/env python 
# -*- coding: utf-8 -*-

# *************************************************************
#     Filename @  objvar.py
#       Author @  Huoty
#  Create date @  2014-10-23 08:50:34
#  Description @  类的变量与对象的变量
# *************************************************************

class Person:
    '''Represents a person.'''
    population = 0 # 人口 

    def __init__(self, name):  # 构造函数, self 是指实例化的对象本身
        '''Initializes the person's data.'''
        self.name = name
        print "(Initiaalizing %s)" % self.name  # 对象的变量

        # When this person is created, he/she
        # adds to the population
        Person.population += 1  # 类变量

    def __del__(self):  # 析构函数
        '''I am dying.'''
        print "%s says bye." % self.name

        Person.population -= 1

        if Person.population == 0:
            print "I am last one"
        else:
            print "There are still %d pepple left." % Person.population

    def sayHi(self):
        '''
        Greeting by the person.
        Really, that's all it does.
        '''
        print "Hi, my name is %s." % self.name

    def howMany(self):
        '''
        Prints the current population.
        '''
        if Person.population == 1:
            print "I am the only person here."
        else:
            print "We have %d persons here." % Person.population

# Script starts from here

swaroop = Person("Swaroop")
swaroop.sayHi()
swaroop.howMany()

kalam = Person("Abdul Kalam")
kalam.sayHi()
kalam.howMany()

swaroop.sayHi()
swaroop.howMany()

